from db import Session
from db.bidding import ShopEleInfo


def geteleIdByShopAccount(account):
    """
    通过account获取id
    :param shopId:
    :return:
    """
    session = Session()
    try:
        account = session.query(ShopEleInfo.id).filter(ShopEleInfo.account == account).scalar()
        if account:
            return account
        else:
            return -1
    except:
        session.rollback()
        return -1
    finally:
        session.close()

def getAllEleShop():
    """获取所有的饿了么店铺"""
    session = Session()
    try:
        shopInfo = session.query(ShopEleInfo.eleName, ShopEleInfo.cookies).filter(ShopEleInfo.deleted == 0).all()
        if shopInfo:
            return shopInfo
        else:
            return 0
    except:
        session.rollback()
        return 0
    finally:
        session.close()